import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GTabBar } from "../../../../com/mui/controls/GTabBar";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { ObjectItem } from "./ObjectItem";
import { ELottertType } from "../../../../Message/Public/ELottertType";
import { ExplorerItemConfig } from "../../resource/ExplorerItemConfig";
import { ExplorerItemInfo } from "../../model/ExplorerItemInfo";
import { ItemData } from "../../resource/info/ItemData";
import { Cache } from "../../cache/Cache";
//class TreasureListWindow
    
    export  class TreasureListWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._itemArr = [];
            setSize(360, 245);
            title = Language.getString(35031);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(18, 62, 323, 172, this);
            this._rTabBarName = Language.getArray(35032);
            this._rTabBar = new GTabBar();
            this._rTabBar.buttonWidth = 80;
            this._rTabBar.x = 16;
            this._rTabBar.y = 34;
            this._rTabBar.horizontalGap = 2;
            this._rTabBar.buttonFilters = [FilterConst.glowFilter];
            this._rTabBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onTabBarSelectedHandler);
            this._rTabBar.selectedIndex = 0;
            addChild(this._rTabBar);
            this.updateListTabBar();
            this.initItems();
            this.onTabBarSelectedHandler();
            return;
        }

        /* internal  */initItems(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            if (this._itemArr.length == 0) 
            {
                loc2 = 23;
                loc3 = 70;
                loc4 = 0;
                while (loc4 < 32) 
                {
                    loc1 = new ObjectItem();
                    loc1.setSize(33, 33);
                    loc1.move(loc2, loc3);
                    addChild(loc1);
                    loc2 = loc2 + 40;
                    if ((loc4 + 1) % 8 == 0) 
                    {
                        loc2 = 23;
                        loc3 = loc3 + 40;
                    }
                    this._itemArr.push(loc1);
                    ++loc4;
                }
            }
            return;
        }

        /* internal  */onTabBarSelectedHandler(arg1: MuiEvent=null): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=ELottertType._ELotterySeabed;
            var loc6=this._rTabBar.selectedIndex;
            switch (loc6) 
            {
                case 0:
                {
                    loc1 = ELottertType._ELotterySeabed;
                    break;
                }
                case 1:
                {
                    loc1 = ELottertType._ELotteryHeaven;
                    break;
                }
                case 2:
                {
                    loc1 = ELottertType._ELotteryKunlun;
                    break;
                }
            }
            var loc4=ExplorerItemConfig.instance.getItemInfoByType(loc1);
            var loc5=0;
            loc5 = 0;
            while (loc5 < this._itemArr.length) 
            {
                loc3 = this._itemArr[loc5] as ObjectItem;
                if (loc4[loc5] == null) 
                {
                    loc3.itemData = null;
                }
                else 
                {
                    loc2 = loc4[loc5] as ExplorerItemInfo;
                    loc3.itemData = new ItemData(loc2.item);
                }
                ++loc5;
            }
            return;
        }

        public updateListTabBar(): void
        {
            var loc1=Cache.instance.role.entityInfo.level;
            var loc2=[];
            if (loc1 < 55) 
            {
                loc2 = [this._rTabBarName[0]];
            }
            else if (loc1 >= 55 && loc1 < 100) 
            {
                loc2 = [this._rTabBarName[0], this._rTabBarName[1]];
            }
            else if (loc1 >= 100) 
            {
                loc2 = [this._rTabBarName[0], this._rTabBarName[1], this._rTabBarName[2]];
            }
            this._rTabBar.dataProvider = loc2;
            return;
        }

        /* internal */ /* var */_rTabBar: GTabBar;

        /* internal */ /* var */_rTabBarName: Array<any>;

        /* internal */ /* var */_itemArr: Array<any>;
    }
